home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / pgm_util / editbats / editbats.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-12-27  |  25.4 KB  |  575 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3555
  6.    ClientLeft      =   2265
  7.    ClientTop       =   2475
  8.    ClientWidth     =   7515
  9.    ClipControls    =   0   'False
  10.    Height          =   3960
  11.    Left            =   2205
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3555
  16.    ScaleWidth      =   7515
  17.    Top             =   2130
  18.    Width           =   7635
  19.    Begin TextBox Text1 
  20.       Height          =   1005
  21.       Left            =   1770
  22.       MultiLine       =   -1  'True
  23.       ScrollBars      =   2  'Vertical
  24.       TabIndex        =   4
  25.       Text            =   "Text1"
  26.       Top             =   795
  27.       Width           =   3150
  28.    End
  29.    Begin CommandButton BTN_Read 
  30.       Caption         =   "Read Docs"
  31.       Height          =   500
  32.       Left            =   3100
  33.       TabIndex        =   3
  34.       Top             =   3000
  35.       Width           =   1215
  36.    End
  37.    Begin CommandButton BTN_Quit 
  38.       Caption         =   "Quit"
  39.       Height          =   500
  40.       Left            =   4800
  41.       TabIndex        =   2
  42.       Top             =   3000
  43.       Width           =   1215
  44.    End
  45.    Begin CommandButton BTN_Proceed 
  46.       Caption         =   "Proceed"
  47.       Height          =   500
  48.       Left            =   1400
  49.       TabIndex        =   1
  50.       Top             =   3000
  51.       Width           =   1215
  52.    End
  53.    Begin Label Label1 
  54.       Caption         =   "Label1"
  55.       Height          =   2925
  56.       Left            =   30
  57.       TabIndex        =   0
  58.       Top             =   30
  59.       Width           =   7470
  60.    End
  61. 'Function Declarations
  62. Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  63. Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)
  64. Declare Function FindExecutable Lib "shell.dll" (ByVal lpszFile$, ByVal lpszDir$, ByVal lpszResult$) As Integer
  65. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  66. Declare Function WriteProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String) As Integer
  67. Declare Function PostMessageByString% Lib "User" Alias "PostMessage" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam$)
  68. Declare Function ExitWindows Lib "User" (ByVal RestartCode As Long, ByVal DOSReturnCode As Integer) As Integer
  69. Declare Function GetVersion Lib "Kernel" () As Long
  70. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
  71. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  72. ' API functions used in getting user and company name
  73. Declare Function LoadLibrary% Lib "Kernel" (ByVal LibFileName$)
  74. Declare Sub FreeLibrary Lib "Kernel" (ByVal hInst%)
  75. Declare Function LoadString% Lib "User" (ByVal hInst%, ByVal idResource%, ByVal Buffer$, ByVal cBuffer%)
  76. 'Constants
  77. Const HWND_BROADCAST = &HFFFF
  78. Const WM_WININICHANGE = &H1A
  79. Const WM_USER = &H400
  80. Const EM_SETREADONLY = WM_USER + 31
  81. Const WM_SYSCOMMAND = &H112
  82. Const SC_CLOSE = &HF060
  83. 'Variables
  84. Dim ProgramName As String
  85. Dim CRLF As String
  86. Dim UserName As String
  87. Dim IsWin31 As Integer
  88. Dim GroupName As String
  89. Dim FMFlag As Integer
  90. Sub BTN_Proceed_Click ()
  91.     'Check if File Manager is running
  92.     FMFlag = CloseFileMan()
  93.     'Call the function which determines if and what app is
  94.     'associated with the .txt extension
  95.     TestResult = PerformTest()
  96.     'If Text files are not associated with any app and the
  97.     'user chose not to make an association, end the program.
  98.     If TestResult = 4 Then Unload Me
  99.     Dim WinDir1 As String * 128
  100.     Dim WinDirSize As Integer
  101.     WinDirSize = 128
  102.     'Get the Windows directory, variables must be defined as above
  103.     Ret = GetWindowsDirectory(WinDir1, WinDirSize)
  104.     WinDir = LCase(Left$(WinDir1, Ret))
  105.      
  106.     'Change to the Windows directory and make backup files
  107.     'of WIN.INI and REG.DAT
  108.     ChDir WinDir
  109.     'Before backing up the files, check if the backup filenames already exist
  110.     If FileExists("reg.bak") Then
  111.         Msg$ = "REG.BAK already exists in your Windows directory." + CRLF + CRLF
  112.         Msg$ = Msg$ + "OK to overwrite?"
  113.         Ans% = MsgBox(Msg$, 52, "File Exists")
  114.     End If
  115.     If Ans% <> 7 Then
  116.         FileCopy "reg.dat", "reg.bak"
  117.         RegBackedUp = True
  118.     End If
  119.     Ans% = 0  'Reset variable
  120.     If FileExists("win.bak") Then
  121.         Msg$ = "WIN.BAK already exists in your Windows directory." + CRLF + CRLF
  122.         Msg$ = Msg$ + "OK to overwrite?"
  123.         Ans% = MsgBox(Msg$, 52, "File Exists")
  124.     End If
  125.     If Ans% <> 7 Then
  126.         FileCopy "win.ini", "win.bak"
  127.         WinBackedUp = True
  128.     End If
  129.      
  130.     'Inform the user of completed step
  131.     If RegBackedUp Then
  132.         Msg$ = "Your original REG.DAT file has been backed up to REG.BAK." + CRLF + CRLF
  133.     Else
  134.         Msg$ = "Your original REG.DAT file was NOT backed up because REG.BAK already exists." + CRLF + CRLF
  135.     End If
  136.     If WinBackedUp Then
  137.         Msg$ = Msg$ + "Your original WIN.INI has been backed up to WIN.BAK."
  138.     Else
  139.         Msg$ = Msg$ + "Your original WIN.INI file was NOT backed up because WIN.BAK already exists."
  140.     End If
  141.     MsgBox Msg$, 64, "Batch File Configuration"
  142.     'Modify the WIN.INI file
  143.     a% = WriteProfileString("windows", "programs", "com exe pif")
  144.     If a% Then
  145.         'Inform the user of completed step
  146.         Msg$ = "WIN.INI has been successfully updated."
  147.         MsgBox Msg$, 64, "Batch File Configuration"
  148.         di% = PostMessageByString(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")
  149.     Else
  150.         'If the function was unsuccesful, inform the user, restore the original
  151.         'WIN.INI, delete the backup files and end the program
  152.         'It is not necessary to restore REG.DAT because it hasn't been altered yet.
  153.         Msg$ = "WIN.INI could not be updated.  Aborting procedure.  " + CRLF
  154.         Msg$ = Msg$ + "Your original WIN.INI and REG.DAT files have been restored."
  155.         FileCopy "win.bak", "win.ini"
  156.         Kill "reg.bak"
  157.         Kill "win.bak"
  158.         MsgBox Msg$, 48, "Batch File Configuration"
  159.         Unload Me
  160.     End If
  161.     'Change to the program's directory
  162.     ChDir app.Path
  163.     'Create the appropriate .REG file based on the test result done earlier
  164.     Select Case TestResult
  165.     Case 1
  166.         FileNum = FreeFile
  167.         Open "batch.reg" For Output As FileNum
  168.         Print #FileNum, "REGEDIT"
  169.         Print #FileNum, "HKEY_CLASSES_ROOT\.bat = txtfile"
  170.         Close FileNum
  171.     Case 2
  172.         FileNum = FreeFile
  173.         Open "batch.reg" For Output As FileNum
  174.         Print #FileNum, "REGEDIT"
  175.         Print #FileNum, "HKEY_CLASSES_ROOT\.bat\shell\open\command = " & ProgramName & " %1"
  176.         Close FileNum
  177.     Case 3
  178.         FileNum = FreeFile
  179.         Open "batch.reg" For Output As FileNum
  180.         Print #FileNum, "REGEDIT"
  181.         Print #FileNum, "HKEY_CLASSES_ROOT\txtfile = Text File"
  182.         Print #FileNum, "HKEY_CLASSES_ROOT\.bat = txtfile"
  183.         Print #FileNum, "HKEY_CLASSES_ROOT\.ini = txtfile"
  184.         Print #FileNum, "HKEY_CLASSES_ROOT\.txt = txtfile"
  185.         Print #FileNum, "HKEY_CLASSES_ROOT\txtfile\shell\print\command = notepad.exe /p %1"
  186.         Print #FileNum, "HKEY_CLASSES_ROOT\txtfile\shell\open\command = notepad.exe %1"
  187.         Close FileNum
  188.     End Select
  189.     'Allow Windows time to process file i/o
  190.     DoEvents
  191.     'Shell to the Registration Editor program, using the file just created
  192.     'as a command line argument.  This will automatically update the Registration
  193.     'Database
  194.     x% = Shell("regedit.exe " + app.Path + "\BATCH.REG")
  195.         
  196.     'Wait for the user to click the Registration Database's OK button
  197.     'before continuing with the program.
  198.     While GetModuleUsage(x%) > 0
  199.         Z% = DoEvents()
  200.         'Disable the form so the user cannot interact with it
  201.         Form1.Enabled = False
  202.     Wend
  203.     'Delete the file that was just created
  204.     Kill "batch.reg"
  205.     'Re-Enable the form
  206.     Form1.Enabled = True
  207.     'Call the subroutine asking the user whether to change ProgMan's caption
  208.     ChangeProgMan
  209.     'Prompt the user to restart Windows.  While it's not absolutely necessary to restart
  210.     'since the change to WIN.INI is broadcast to all apps and the Registration
  211.     'Editor automatically broadcasts, it's better to do so, if for no other reason
  212.     'than to update ProgMan's caption (if the user chose to do this).  Also, if
  213.     'File Manager was running during this procedure, the document-file icons will
  214.     'not be updated until FM is restarted, even though the association does exist.
  215.     Msg$ = "Windows should now be restarted to verify that all is well.  "
  216.     Msg$ = Msg$ + "If Windows fails to restart, change to your Windows directory "
  217.     Msg$ = Msg$ + "and rename REG.BAK and WIN.BAK to REG.DAT and WIN.INI.  This "
  218.     Msg$ = Msg$ + "will restore your original configuration."
  219.     If MsgBox(Msg$, 4 + 32 + 256, "Batch File Configuration") <> 6 Then
  220.          'If the answer was NO, simply end the program
  221.          Unload Me
  222.     End If
  223.     'Call the function to restart Windows
  224.     i = ExitWindows(66, 0)
  225.     'The function will return 0 if any app fails to close
  226.     If i = 0 Then
  227.         'Inform the user to close Windows normally
  228.         Msg$ = "One or more applications refused to terminate.  This is "
  229.         Msg$ = Msg$ + "probably due to a DOS program that is running in the "
  230.         Msg$ = Msg$ + "background or a Windows program that has unsaved data.  "
  231.         Msg$ = Msg$ + "Click OK, then shut down "
  232.         Msg$ = Msg$ + "and restart Windows manually."
  233.         MsgBox Msg$, 48, "Batch File Configuration"
  234.     End If
  235.     'Unload the form and end the program
  236.     Unload Me
  237. End Sub
  238. Sub BTN_Quit_Click ()
  239.     Unload Me
  240. End Sub
  241. Sub BTN_Read_Click ()
  242.     On Error Resume Next
  243.     Dim FileText As String
  244.     FileNum = FreeFile
  245.     FileText = ""
  246.     FileName$ = app.Path + "\editbats.txt"
  247.     'Open the file for reading
  248.     Open FileName$ For Input As FileNum
  249.     If Err Then
  250.         Close
  251.         MsgBox "Error opening " + FileName$ + CRLF + CRLF + Error$, 64
  252.         Exit Sub
  253.     End If
  254.     'Read each line into a buffer then assign that buffer to a variable and
  255.     'append a carriage return and line feed at the end of each line
  256.     Do Until EOF(FileNum)
  257.         Line Input #FileNum, a$
  258.         FileText = FileText + a$ + CRLF
  259.     Loop
  260.     Close FileNum
  261.     'Set the dimmensions of the text box the same as the label
  262.     Text1.Width = Label1.Width
  263.     Text1.Height = Label1.Height
  264.     Text1.Top = Label1.Top
  265.     Text1.Left = Label1.Left
  266.     'Assign the contents of the file to the text box
  267.     Text1 = FileText
  268.     'Unhide the text box
  269.     Text1.Visible = True
  270.     'Enable the Proceed button
  271.     BTN_Proceed.Enabled = True
  272.     'Disable the Read Docs button
  273.     BTN_Read.Enabled = False
  274. End Sub
  275. Sub ChangeProgMan ()
  276.     Msg$ = "Want to personalize Program Manager a bit?" + CRLF + CRLF
  277.     Msg$ = Msg$ + "Click the Yes Button to change Program Manager's caption "
  278.     Msg$ = Msg$ + "from reading ""Program Manager"" to ""<yourname>'s Desktop.""" + CRLF + CRLF
  279.     Msg$ = Msg$ + "This is accomplished simply by adding an icon for Program Manager "
  280.     Msg$ = Msg$ + "to the Startup group and changing the Description that appears in "
  281.     Msg$ = Msg$ + "the Program Item Properties box."
  282.     Ans% = MsgBox(Msg$, 36, "Personalize Program Manager")
  283.     'If NO was chosen, exit the sub
  284.     If Ans% = 7 Then
  285.         Exit Sub
  286.     End If
  287.         
  288.     'Call the sub which gets the name of the user from Windows' resources
  289.     GetUserName
  290.     'If the user had clicked the Cancel button in either of the Input Boxes,
  291.     'UserName will be a zero-length string.  Check this and exit the sub, if
  292.     'appropriate
  293.     If UserName = "" Then
  294.         Exit Sub
  295.     End If
  296.     'The CreateProgManItem sub uses this variable
  297.     GroupName = "Startup"
  298.     'Call the sub which creates the Startup group.  There is no harm in doing this
  299.     'even if the Startup group already exists.
  300.     Call CreateProgManGroup(Form1, GroupName, GroupName + ".grp")
  301.     'Call the sub which creates the Program Manager icon in the Startup group
  302.     Call CreateProgManItem(Form1, "progman.exe", UserName + "'s Desktop")
  303. End Sub
  304. Function CloseFileMan ()
  305.     'This function will return TRUE only if File Manager was running and closed,
  306.     'It returns FALSE for any other condition.
  307.     'This value is then used to determine if the program should later restart FM.
  308.     CloseFileMan = False
  309.     'Check to see if File Manager is running
  310.     FileManHandle = FindWindow("WFS_FRAME", "File Manager")
  311.     If FileManHandle Then
  312.         'If it is, prompt to close it
  313.         Msg$ = "It has been detected that File Manager is currently running.  "
  314.         Msg$ = Msg$ + "While this in no way interferes with the procedure, File "
  315.         Msg$ = Msg$ + "Manager should be closed and re-started so that the "
  316.         Msg$ = Msg$ + "document-file icons are properly updated." + CRLF + CRLF
  317.         Msg$ = Msg$ + "Click OK to close File Manager and have it automatically "
  318.         Msg$ = Msg$ + "restarted upon completion, or click Cancel to leave File "
  319.         Msg$ = Msg$ + "Manager running."
  320.         Ans% = MsgBox(Msg$, 65, "File Manager Running")
  321.             
  322.         If Ans% = 1 Then  'OK was clicked
  323.             'Send a system message ordering FM to close.  Zero is returned
  324.             'if FM process the message.
  325.             Success% = SendMessage(FileManHandle, WM_SYSCOMMAND, SC_CLOSE, 0)
  326.             If Success% <> 0 Then
  327.                 Msg$ = "File Manager failed to close." + CRLF
  328.                 Msg$ = Msg$ + "Click OK and continue with the procedure.  You will "
  329.                 Msg$ = Msg$ + "have to close and re-start File Manager manually."
  330.                 MsgBox Msg$, 16, "File Manager Running"
  331.             Else
  332.                 CloseFileMan = True
  333.             End If
  334.         End If
  335.     End If
  336. End Function
  337. Sub CreateProgManGroup (x As Form, GroupName$, GroupPath$)
  338. 'This sub and CreateProgManItem were taken directly from VB's
  339. 'Setup program example
  340. '-------------------------------------------------------------
  341. ' Procedure: CreateProgManGroup
  342. ' Arguments: X           The Form where a Label1 exist
  343. '            GroupName$  A string that contains the group name
  344. '            GroupPath$  A string that contains the group file
  345. '                        name  ie 'myapp.grp'
  346. '-------------------------------------------------------------
  347.     Screen.MousePointer = 11
  348.     '----------------------------------------------------------------------
  349.     ' Windows requires DDE in order to create a program group and item.
  350.     ' Here, a Visual Basic label control is used to generate the DDE messages
  351.     '----------------------------------------------------------------------
  352.     On Error Resume Next
  353.     '--------------------------------
  354.     ' Set LinkTopic to PROGRAM MANAGER
  355.     '--------------------------------
  356.     x.Label1.LinkTopic = "ProgMan|Progman"
  357.     x.Label1.LinkMode = 2
  358.     For i% = 1 To 10                                         ' Loop to ensure that there is enough time to
  359.       Z% = DoEvents()                                        ' process DDE Execute.  This is redundant but needed
  360.     Next                                                     ' for debug windows.
  361.     x.Label1.LinkTimeout = 100
  362.     '---------------------
  363.     ' Create program group
  364.     '---------------------
  365.     x.Label1.LinkExecute "[CreateGroup(" + GroupName$ + Chr$(44) + GroupPath$ + ")]"
  366.     '-----------------
  367.     ' Reset properties
  368.     '-----------------
  369.     x.Label1.LinkTimeout = 50
  370.     x.Label1.LinkMode = 0
  371.     Screen.MousePointer = 0
  372. End Sub
  373. '----------------------------------------------------------
  374. ' Procedure: CreateProgManItem
  375. ' Arguments: X           The form where Label1 exists
  376. '            CmdLine$    A string that contains the command
  377. '                        line for the item/icon.
  378. '                        ie 'c:\myapp\setup.exe'
  379. '            IconTitle$  A string that contains the item's
  380. '                        caption
  381. '----------------------------------------------------------
  382. Sub CreateProgManItem (x As Form, CmdLine$, IconTitle$)
  383.     Screen.MousePointer = 11
  384.     '----------------------------------------------------------------------
  385.     ' Windows requires DDE in order to create a program group and item.
  386.     ' Here, a Visual Basic label control is used to generate the DDE messages
  387.     '----------------------------------------------------------------------
  388.     On Error Resume Next
  389.     '---------------------------------
  390.     ' Set LinkTopic to PROGRAM MANAGER
  391.     '---------------------------------
  392.     x.Label1.LinkTopic = "ProgMan|Progman"
  393.     x.Label1.LinkMode = 2
  394.     For i% = 1 To 10                                         ' Loop to ensure that there is enough time to
  395.       Z% = DoEvents()                                        ' process DDE Execute.  This is redundant but needed
  396.     Next                                                     ' for debug windows.
  397.     x.Label1.LinkTimeout = 100
  398.     '------------------------------------------------
  399.     ' Create Program Item, one of the icons to launch
  400.     ' an application from Program Manager
  401.     '------------------------------------------------
  402.     x.Label1.LinkExecute "[ShowGroup(" + GroupName + ", 1)]"       ' This will ensure that Program Manager does not
  403.     If IsWin31 Then
  404.         ' Win 3.1 has a ReplaceItem, which will allow us to replace existing icons
  405.         x.Label1.LinkExecute "[ReplaceItem(" + IconTitle$ + ")]"
  406.     End If                                                                ' have a Maximized group, which causes problem in RestoreProgMan
  407.     x.Label1.LinkExecute "[AddItem(" + CmdLine$ + Chr$(44) + IconTitle$ + Chr$(44) + ",,)]"
  408.     '-----------------
  409.     ' Reset properties
  410.     '-----------------
  411.     x.Label1.LinkTimeout = 50
  412.     x.Label1.LinkMode = 0
  413.     Screen.MousePointer = 0
  414. End Sub
  415. Function FileExists (FileName As String) As Integer
  416.     'This sub checks for the existance of any filename passed to it
  417.     If Len(Dir$(FileName)) Then
  418.         FileExists = True
  419.     Else
  420.         FileExists = False
  421.     End If
  422. End Function
  423. Function FixAmpersand$ (ByVal Buffer As String)
  424.   'Sometimes an ampersand (&) is included in the string.
  425.   'This function will get rid of it and also any characters
  426.   'that have no graphical representation (such as TAB or
  427.   'Carriage Return) at the end of the name.
  428.   Dim N%
  429.   N = 1
  430.   Do Until N = 0
  431.     N = InStr(N, Buffer, "&")
  432.     If N > 0 Then
  433.       Buffer = Left$(Buffer, N) + Mid$(Buffer, N)
  434.       N = N + 2
  435.     End If
  436.   Loop
  437.   Do While Right$(Buffer, 1) = Chr$(0)
  438.     Buffer = Left$(Buffer, Len(Buffer) - 1)
  439.   Loop
  440.   FixAmpersand = Buffer
  441. End Function
  442. Sub Form_Load ()
  443.     'Get the Windows version
  444.     VerInfo& = GetVersion()
  445.     WinVer& = VerInfo& And &HFFFF&
  446.     If Val(Format$(WinVer& Mod 256) + "." + Format$(WinVer& \ 256)) >= 3.1 Then
  447.         IsWin31 = True
  448.     End If
  449.     'Center the form on the desktop
  450.     Move (Screen.Width - Width) \ 2, ((Screen.Height - Height) \ 2 - 200)
  451.     'Define a Carriage Return and Line Feed
  452.     CRLF = Chr$(13) + Chr$(10)
  453.     'Set the form's caption
  454.     Form1.Caption = "Batch File Configuration"
  455.     'Define message and assign it to the label
  456.     Msg$ = "This program alters important Windows configuration files.  "
  457.     Msg$ = Msg$ + "Your original files will be backed up before any changes "
  458.     Msg$ = Msg$ + "are made to them." + CRLF + CRLF
  459.     Msg$ = Msg$ + "Before you can continue with the process, you MUST read "
  460.     Msg$ = Msg$ + "the text file by clicking on the Read Docs button." + CRLF + CRLF
  461.     Msg$ = Msg$ + "After reading the documentation, click the Proceed "
  462.     Msg$ = Msg$ + "button to continue or the Quit button "
  463.     Msg$ = Msg$ + "to cancel." + CRLF + CRLF
  464.     Msg$ = Msg$ + "Once you have started the process, you must complete it.  "
  465.     Msg$ = Msg$ + "You cannot cancel after clicking on Proceed, so be sure "
  466.     Msg$ = Msg$ + "that you understand what changes are being made." + CRLF + CRLF
  467.     Msg$ = Msg$ + "After receiving confirmation of the procedure, you should "
  468.     Msg$ = Msg$ + "restart Windows." + CRLF + CRLF
  469.     Label1 = Msg$
  470.     'Disable the Proceed button
  471.     BTN_Proceed.Enabled = False
  472.     'Make the text box READONLY
  473.     a% = SendMessage(Text1.hWnd, EM_SETREADONLY, True, 0&)
  474.     'Hide the text box
  475.     Text1.Visible = False
  476. End Sub
  477. Sub Form_Unload (Cancel As Integer)
  478.     'Make sure that all files have been closed
  479.     Close
  480.     'If File Manager was running prior to this program and closed,
  481.     'restart it.
  482.     If FMFlag Then
  483.         x% = Shell("winfile.exe", 1)
  484.     End If
  485.     End
  486. End Sub
  487. Sub GetUserName ()
  488.         
  489.         'Get access to USER's strings by getting a handle to USER
  490.         Dim hInstUser As Integer
  491.         hInstUser = LoadLibrary("USER")
  492.         FreeLibrary hInstUser
  493.       
  494.         Dim Buffer As String, Success As Integer, N As Integer
  495.       
  496.         'Get the User name
  497.         'The string used to hold the name must be fixed-length
  498.         Buffer = String$(31, 0)
  499.         If LoadString(hInstUser, 514, Buffer, 30) Then
  500.             UserName = Trim(FixAmpersand(Buffer))
  501.             
  502.             'Trim it down to just the first name
  503.             SpacePos = InStr(UserName, " ")
  504.             UserName = Left$(UserName, SpacePos - 1)
  505.             'Verify the users' name that was retrieved.
  506.             'Most users probably used their full name when installing
  507.             'Windows, but would rather use a shorter name for this.
  508.             'For example, I used "Michael" during my Windows installation,
  509.             'but prefer to use "Mike".  So why even go through the process
  510.             'of getting the user's name?  Well, it looks good! :)
  511.             Msg$ = "Click OK to use the name below or type in a new first name."
  512.             UserName = InputBox$(Msg$, "Personalize Program Manager", UserName)
  513.         Else
  514.             'For some reason, a name couldn't be found, so prompt for it
  515.             Msg$ = "Could not find the name of the person this copy of Windows is registered to." + CRLF
  516.             Msg$ = Msg$ + "Please type in your first name."
  517.             UserName = InputBox(Msg$, "Personalize Program Manager")
  518.         End If
  519. End Sub
  520. Function PerformTest ()
  521.     'Returns 1 if text files are associated with Notepad
  522.     'Returns 2 if text files are associated with an application other than Notepad
  523.     'Returns 3 if an association was not found and user chooses to make the association
  524.     'Returns 4 if an association was not found and user chooses to not make the association
  525.     'This variable must be a fixed-length string
  526.     Dim Association As String * 129
  527.     'This function will find what app is associated with a given extension
  528.     x% = FindExecutable("editbats.txt", app.Path, Association)
  529.     'A character which has an ANSI value of 0 separates the executable
  530.     'filename from the specified filename.  Use this to strip away the
  531.     'executable filename
  532.     NullPos = InStr(Association, Chr$(0))
  533.     If NullPos = 1 Then
  534.         'If the string begins with ANSI Code 0,
  535.         'an association does not exist.  Create
  536.         'a zero-length string.
  537.         ProgramName = ""
  538.     Else
  539.         ProgramName = Mid$(Association, 1, NullPos - 1)
  540.     End If
  541.     If LCase$(Left$(ProgramName, 7)) = "notepad" Then
  542.         'Text files are associated with Notepad.  This is
  543.         'Windows default association.
  544.         Msg$ = "Your system associates text files with Notepad." + CRLF
  545.         Msg$ = Msg$ + "Batch files will also be associated with Notepad."
  546.         MsgBox Msg$, 64, "Association Found"
  547.         PerformTest = 1
  548.     ElseIf Len(ProgramName) Then
  549.         'Text files are associated with a different program.
  550.         Msg$ = "Your system associates text files with the following program:" + CRLF + CRLF
  551.         Msg$ = Msg$ + UCase$("                                     " + ProgramName + CRLF + CRLF)
  552.         Msg$ = Msg$ + "Batch files will also be associated with " + UCase$(ProgramName) + "."
  553.         MsgBox Msg$, 64, "Association Found"
  554.         PerformTest = 2
  555.     Else
  556.         'An association was not found, so ask the user if Windows default
  557.         'association should be created.
  558.         Msg$ = "Your system contains no association between text files and an"
  559.         Msg$ = Msg$ + " application.  Do you want to create an association "
  560.         Msg$ = Msg$ + "between Notepad and the following extensions?" + CRLF + CRLF
  561.         Msg$ = Msg$ + "                          *.txt" + CRLF
  562.         Msg$ = Msg$ + "                          *.bat" + CRLF
  563.         Msg$ = Msg$ + "                          *.ini" + CRLF
  564.         a% = MsgBox(Msg$, 52, "Association not Found")
  565.         
  566.         If a% = 6 Then
  567.             'If the user answered YES...
  568.             PerformTest = 3
  569.         Else
  570.             'If the user answered NO...
  571.             PerformTest = 4
  572.         End If
  573.     End If
  574. End Function
  575.